import pymysql

# 连接到MySQL数据库
# 连接数据库
conn = pymysql.connect(host='localhost', port=3306, user='', password='', database='')
# 创建一个cursor对象
cursor = conn.cursor()
# frequently used port  oracle: 1521   mysql:3306  postgreSQL:5432  http:8080
try:
    # 执行一个查询
    cursor.execute("SELECT * FROM your_table")
    # 获取查询结果
    records = cursor.fetchall()
    # 遍历结果
    for row in records:
        print(row)

except conn.Error as error:
    print("Failed to connect to database: {}".format(error))

finally:
    # if conn.is_connected():
    cursor.close()
    conn.close()
    print("MySQL connection is closed")

